#ifndef __SPIKED_PLANK_BLOCK_H__
#define __SPIKED_PLANK_BLOCK_H__

#include "Block.hpp"
#include "Components/ComponentMiner.h"
#include "Components/ComponentCreature.h"
#include "Components/ComponentCreatureModel.h"
#include "Terrain/Terrain.h"

namespace PocketSurvival
{
    // 木刺陷阱, 未完成...  未添加电路支持
    class SpikedPlankBlock : public Block
    {
    public:
        static constexpr int32_t Index()
        {
            return 86;
        }
        virtual int32_t getIndex() override;
        virtual const std::string &getBlockName() override;

        virtual bool isFaceTransparent(int32_t face, int32_t value) override;
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;
        virtual const std::vector<BoundingBox> &getCustomCollisionBoxes(int32_t value) override;
        virtual bool shouldAvoid(int32_t value) override;

        static inline bool GetSpikesState(int32_t data);
        static inline int32_t SetSpikesState(int32_t data, bool spikesState);
        static inline int32_t GetMountingFace(int32_t data);
        static inline int32_t SetMountingFace(int32_t data, int32_t face);
    };

    inline bool SpikedPlankBlock::GetSpikesState(int32_t data)
    {
        return 0 == (data & 1);
    }
    inline int32_t SpikedPlankBlock::SetSpikesState(int32_t data, bool spikesState)
    {
        if (spikesState)
        {
            return (data & -2);
        }
        return (data | 1);
    }

    inline int32_t SpikedPlankBlock::GetMountingFace(int32_t data)
    {
        return ((data >> 1) + 4) % 6;
    }
    inline int32_t SpikedPlankBlock::SetMountingFace(int32_t data, int32_t face)
    {
        data &= -15;
        data |= (((face + 2) % 6) & 7) << 1;
        return data;
    }

} // namespace PocketSurvival

#endif
